package cn.tedu.fy.pethome.controller;

import cn.tedu.fy.pethome.pojo.dto.PetAddNewDTO;
import cn.tedu.fy.pethome.pojo.vo.GoodsDetailVO;
import cn.tedu.fy.pethome.pojo.vo.GoodsListItemsVO;
import cn.tedu.fy.pethome.service.IPetService;
import cn.tedu.fy.pethome.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商品的controller
 *
 * @author KJ2476
 * @date 2022/7/21
 */
@Slf4j
@RestController
@RequestMapping("/pets")
@Api(tags = "宠物")
public class PetController {
    @Autowired
    IPetService petService;

    @ApiOperation("添加宠物")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult petAddNew(PetAddNewDTO petAddNewDTO) {
        log.debug("接收到添加宠物的请求,参数为：{}", petAddNewDTO);
        petService.petAddNew(petAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("查询商品列表")
    @ApiOperationSupport(order = 401)
    @GetMapping("/list")
    public JsonResult list(){
        log.debug("处理查询商品列表");
        List<GoodsListItemsVO> goods = petService.list();
        return JsonResult.ok(goods);
    }

    @ApiOperation("根据类别id查询商品列表")
    @ApiOperationSupport(order = 402)
    @GetMapping("/getByCategoryId")
    public JsonResult getByCategoryId(Long cid){
        log.debug("处理根据类别名称查询商品列表");
        List<GoodsListItemsVO> goods = petService.getByCategoryId(cid);
        return JsonResult.ok(goods);
    }

    @ApiOperation("根据关键词查询商品列表")
    @ApiOperationSupport(order = 403)
    @GetMapping("/getByWd")
    public JsonResult getByWd(String wd){
        log.debug("处理根据关键词查询商品列表");
        List<GoodsListItemsVO> goods = petService.getByWd(wd);
        return JsonResult.ok(goods);
    }

    @ApiOperation("根据id查询商品详情")
    @ApiOperationSupport(order = 404)
    @GetMapping("/getById")
    public JsonResult getById(String id){
        log.debug("处理根据id查询商品详情");
        GoodsDetailVO goods = petService.getById(id);
        return JsonResult.ok(goods);
    }

}
